package com.dingli.DAO;

import com.dingli.entity.order;
import com.dingli.utils.DataSourceUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.MapListHandler;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class OrderDAO {
    private QueryRunner runner = new QueryRunner(DataSourceUtil.getDataSource());

    public List<Map<String, Object>> listAllTicket(){
        String sql =
                "select " +
                "p.id pid, p.name," +
                "l.lineName, l.passby, l.siteNum," +
                "t.restNumber, t.price, tl.levelName " +
                "from ticketPurchased tp " +
                "inner join person p on tp.personID = p.id " +
                "inner join Ticket t on tp.tktID = t.ticketID " +
                "inner join ticketLevel tl on t.tlevel = tl.tlvID " +
                "inner join line l on t.lineID = l.lineID ";
        try {
//            List<Object> execute = runner.execute(sql, new BeanHandler<>(Object.class));
            List<Map<String, Object>> resultsAsMapList = runner.query(sql, new MapListHandler());
            return resultsAsMapList;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}


